<?php

namespace Modules\System\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Modules\System\Services\Mds\MDSString;

class CheckUser
{
    /**
     * Handle an incoming request.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Closure $next
     * @return mixed
     */
    public function handle(Request $request,Closure $next){

        $REQUEST_URI = strtolower($_SERVER['REQUEST_URI']);

        if(MDSString::contain($REQUEST_URI,'system')){
            return $next($request);                           //有些模块直接放行
        }

        $AuthServices = self::getServices($REQUEST_URI);
        //d($AuthServices);
        //Cache::put('AuthRole', '', 3600);
        //进行权限判断
        if(!in_array($REQUEST_URI,$AuthServices::$noAuth)){
            //获取菜单全新信息
            $AuthRole = $AuthServices::authMenu($REQUEST_URI);
        }else{
            //不进行权限判断，如果需要菜单就进行获取菜单
            if(in_array($REQUEST_URI,$AuthServices::$needMenu)){
                //获取菜单全新信息
                $AuthRole = $AuthServices::authMenu($REQUEST_URI);
            }
        }

        return $next($request);

    }

    /**
     * 不同系统做不同判断
     *
     */
    static protected function getServices(){
        $AuthServices = \Modules\Chinadmin\Services\AuthServices::class;
        return $AuthServices;
    }


}
